package com.innoking.docsys.logger.service.impl;


import com.innoking.docsys.log.module.LoggerVO;
import com.innoking.docsys.logger.dao.master.MasterLogUserLoginDao;
import com.innoking.docsys.logger.service.LoggerCall;
import com.innoking.docsys.logger.service.LoggerService;
import com.innoking.docsys.logger.utils.LoggerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class LoggerServiceIMPL implements LoggerService {

    Logger logger = LoggerFactory.getLogger(LoggerServiceIMPL.class);

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    MasterLogUserLoginDao masterLogUserLoginDao;

    @Override
    public void addLoger(LoggerVO vo) {


        vo.setLogTime(new Date());
        LoggerCall loggerCall=new LoggerLoginCallImpl(redisTemplate,masterLogUserLoginDao);

        if (LoggerUtils.LOGGER_DESTROY.equals( vo.getSysLogicType()) ){
            logger.info(LoggerUtils.LOGGER_DESTROY);
            loggerCall=new LoggerDestroyCallImpl(redisTemplate,masterLogUserLoginDao);
        }else   if (LoggerUtils.LOGGER_EDIT.equals( vo.getSysLogicType()) ){
            logger.info(LoggerUtils.LOGGER_EDIT);
            loggerCall=new LoggerEditCallImpl(redisTemplate,masterLogUserLoginDao);
        }else   if (LoggerUtils.LOGGER_SEARCH.equals( vo.getSysLogicType()) ){
            logger.info(LoggerUtils.LOGGER_SEARCH);
            loggerCall=new LoggerSearchCallImpl(redisTemplate,masterLogUserLoginDao);
        }else   if (LoggerUtils.LOGGER_SYSOPERATION.equals( vo.getSysLogicType()) ){
            logger.info(LoggerUtils.LOGGER_SYSOPERATION);
            loggerCall=new LoggerSysOperationCallImpl(redisTemplate,masterLogUserLoginDao);
        }else   if (LoggerUtils.LOGGER_TRANSFER.equals( vo.getSysLogicType()) ){
            logger.info(LoggerUtils.LOGGER_TRANSFER);
            loggerCall=new LoggerTransferCallImpl(redisTemplate,masterLogUserLoginDao);
        }else  if (LoggerUtils.LOGGER_VIEWDOC.equals( vo.getSysLogicType()) ){
            logger.info(LoggerUtils.LOGGER_VIEWDOC);
            loggerCall=new LoggerDocViewCallImpl(redisTemplate,masterLogUserLoginDao);
        }


        loggerCall.addLogger(vo);
    }
}